{% import 'Dockerfile/docker.jinja2'    as docker %}
{% import 'Dockerfile/provision.jinja2' as provision %}
{% import 'Dockerfile/services.jinja2'  as services %}

{% macro alpine(role='') -%}
    # Install php environment
    && apk-install \
        # Install tools
        imagemagick \
        graphicsmagick \
        ghostscript \
        # Install php (cli/fpm)
        php5-cli \
        php5-fpm \
        php5-json \
        php5-intl \
        php5-imap \
        php5-curl \
        php5-mysql \
        php5-mysqli \
        php5-pdo_mysql \
        php5-pdo_pgsql \
        php5-pdo_sqlite \
        php5-mcrypt \
        php5-gd \
        php5-bcmath \
        php5-soap \
        php5-sqlite3 \
        php5-bz2 \
        php5-calendar \
        php5-ctype \
        php5-mongodb \
        php5-pcntl \
        php5-pgsql \
        php5-posix \
        php5-sockets \
        php5-sysvmsg \
        php5-sysvsem \
        php5-sysvshm \
        php5-xmlreader \
        php5-exif \
        php5-ftp \
        php5-gettext \
        php5-iconv \
        php5-zip \
        php5-zlib \
        php5-shmop \
        php5-wddx \
        sqlite \
        php5-xmlrpc \
        php5-xsl \
        geoip \
        php5-ldap \
        # php5-memcache \
        php5-redis \
        php5-pear \
        php5-phar \
        php5-openssl \
        # php5-apcu \
    && ln -s /usr/bin/php5      /usr/bin/php \
    && ln -s /usr/sbin/php-fpm5 /usr/sbin/php-fpm \
    && ln -s /usr/bin/phpize5 /usr/sbin/phpize \
    && pecl channel-update pecl.php.net \
    # Temporarily disable pear due to https://twitter.com/pear/status/1086634389465956352
    # && pear channel-update pear.php.net \
    # && pear upgrade-all \
    && pear config-set auto_discover 1 \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer2 \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer1 --1 \
    && ln -sf /usr/local/bin/composer2 /usr/local/bin/composer \
    # PECL workaround, see webdevops/Dockerfile#78
    && sed -i "s/ -n / /" $(which pecl) \
    # && apk-install gcc php5-dev autoconf --virtual .pecl-deps \
    # && go-replace  -v -s 'expr -- [$]0 : "'\''.*"' -r 'expr " [$]0" : " '\''.*"' -- /usr/lib/php/build/acinclude.m4
    # && pecl install apcu-4.0.11 \
    # && apk del .pecl-deps \
    {{ services.php() }}
{%- endmacro %}


{% macro centos(role='') -%}
    # Install php environment
    && yum-install \
        # Install tools
        ImageMagick \
        GraphicsMagick \
        ghostscript \
        # Install php (cli/fpm)
        php-cli \
        php-fpm \
        php-json \
        php-intl \
        php-imap \
        php-curl \
        php-mysqlnd \
        php-mongodb \
        php-memcached \
        php-mcrypt \
        php-gd \
        php-pgsql \
        php-mbstring \
        php-bcmath \
        php-soap \
        sqlite \
        php-xmlrpc \
        php-xsl \
        geoip \
        php-ldap \
        php-memcache \
        php-pecl-redis \
        ImageMagick \
        ImageMagick-devel \
        ImageMagick-perl \
        php-pear \
        php-pecl-apcu \
        php-devel \
        gcc \
        php-pear \
    && pecl channel-update pecl.php.net \
    # Temporarily disable pear due to https://twitter.com/pear/status/1086634389465956352
    # && pear channel-update pear.php.net \
    # && pear upgrade-all \
    && pear config-set auto_discover 1 \
    && pecl install imagick \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer2 \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer1 --1 \
    && ln -sf /usr/local/bin/composer2 /usr/local/bin/composer \
    # Cleanup
    && yum erase -y php-devel gcc \
    {{ services.php() }}
{%- endmacro %}

{% macro centosWebtatic(role='') -%}
    && rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm \
    && yum-install \
        ImageMagick \
        GraphicsMagick \
        ghostscript \
        php56w-cli \
        php56w-fpm \
        php56w-common \
        php56w-intl \
        php56w-imap \
        php56w-mysqlnd \
        php56w-pecl-memcached \
        php56w-mongodb \
        php56w-mcrypt \
        php56w-gd \
        php56w-pgsql \
        php56w-mbstring \
        php56w-bcmath \
        php56w-soap \
        sqlite \
        php56w-xmlrpc \
        php56w-xml \
        geoip \
        php56w-ldap \
        ImageMagick-devel \
        ImageMagick-perl \
        php56w-pear \
        php56w-devel \
        gcc \
        make \
        php56w-opcache \
    # Temporarily disable pear due to https://twitter.com/pear/status/1086634389465956352
    # && pear channel-update pear.php.net \
    # && pear upgrade-all \
    && pear config-set auto_discover 1 \
    && sed -i "$ s|\-n||g" /usr/bin/pecl \
    && pecl install imagick \
    # && pecl install redis \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer2 \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer1 --1 \
    && ln -sf /usr/local/bin/composer2 /usr/local/bin/composer \
    # Cleanup
    && yum erase -y php-devel gcc \
    {{ services.php() }}
{%- endmacro %}

{% macro debian7(role='') -%}
    # Install php environment
    && apt-install \
        # Install tools
        imagemagick \
        graphicsmagick \
        ghostscript \
        # Install php (cli/fpm)
        php5-cli \
        php5-fpm \
        php5-json \
        php5-intl \
        php5-imap \
        php5-curl \
        php5-mysqlnd \
        php5-mongodb \
        php5-mcrypt \
        php5-gd \
        php5-sqlite \
        php5-pgsql \
        php5-xmlrpc \
        php5-xsl \
        php5-geoip \
        php5-ldap \
        php5-memcache \
        php5-memcached \
        php5-imagick \
        php-pear \
    && pecl channel-update pecl.php.net \
    # Temporarily disable pear due to https://twitter.com/pear/status/1086634389465956352
    # && pear channel-update pear.php.net \
    # && pear upgrade-all \
    && pear config-set auto_discover 1 \
    && ln -sf /etc/php5/mods-available/mcrypt.in /etc/php5/cli/conf.d/20-mcrypt.ini \
    && ln -sf /etc/php5/mods-available/mcrypt.in /etc/php5/fpm/conf.d/20-mcrypt.ini \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer2 \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer1 --1 \
    && ln -sf /usr/local/bin/composer2 /usr/local/bin/composer \
    {{ services.php() }}
{%- endmacro %}


{% macro debian8(role='') -%}
    # Install php environment
    && apt-install \
        # Install tools
        imagemagick \
        graphicsmagick \
        ghostscript \
        # Install php (cli/fpm)
        php5-cli \
        php5-fpm \
        php5-json \
        php5-intl \
        php5-imap \
        php5-curl \
        php5-mysqlnd \
        php5-mongo \
        php5-mcrypt \
        php5-gd \
        php5-sqlite \
        php5-pgsql \
        php5-xmlrpc \
        php5-xsl \
        php5-geoip \
        php5-ldap \
        php5-memcache \
        php5-memcached \
        php5-imagick \
        php5-redis \
        php5-apcu \
        php-pear \
    && pecl channel-update pecl.php.net \
    # Temporarily disable pear due to https://twitter.com/pear/status/1086634389465956352
    # && pear channel-update pear.php.net \
    # && pear config-set auto_discover 1 \
    && ln -sf /etc/php5/mods-available/mcrypt.in /etc/php5/cli/conf.d/20-mcrypt.ini \
    && ln -sf /etc/php5/mods-available/mcrypt.in /etc/php5/fpm/conf.d/20-mcrypt.ini \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer2 \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer1 --1 \
    && ln -sf /usr/local/bin/composer2 /usr/local/bin/composer \
    {{ services.php() }}
{%- endmacro %}


{% macro debian9(role='') -%}
    # Install php environment
    && apt-install \
        # Install tools
        imagemagick \
        graphicsmagick \
        ghostscript \
        # Install php (cli/fpm)
        php5-cli \
        php5-fpm \
        php5-json \
        php5-intl \
        php5-imap \
        php5-curl \
        php5-mysqlnd \
        php5-mongodb \
        php5-mcrypt \
        php5-gd \
        php5-sqlite \
        php5-pgsql \
        php5-xmlrpc \
        php5-xsl \
        php5-geoip \
        php5-ldap \
        php5-memcache \
        #php-memcached \
        php5-imagick \
        #php5-redis \
        php-pear \
    && pecl channel-update pecl.php.net \
    # Temporarily disable pear due to https://twitter.com/pear/status/1086634389465956352
    # && pear channel-update pear.php.net \
    # && pear upgrade-all \
    && pear config-set auto_discover 1 \
    && ln -sf /etc/php5/mods-available/mcrypt.in /etc/php5/cli/conf.d/20-mcrypt.ini \
    && ln -sf /etc/php5/mods-available/mcrypt.in /etc/php5/fpm/conf.d/20-mcrypt.ini \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer2 \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer1 --1 \
    && ln -sf /usr/local/bin/composer2 /usr/local/bin/composer \
    {{ services.php() }}
{%- endmacro %}

{% macro debian10(role='') -%}
    # Install php environment
    && apt-install \
        # Install tools
        imagemagick \
        graphicsmagick \
        ghostscript \
        # Install php (cli/fpm)
        php5-cli \
        php5-fpm \
        php5-json \
        php5-intl \
        php5-imap \
        php5-curl \
        php5-mysqlnd \
        php5-mongodb \
        php5-mcrypt \
        php5-gd \
        php5-sqlite \
        php5-pgsql \
        php5-xmlrpc \
        php5-xsl \
        php5-geoip \
        php5-ldap \
        php5-memcache \
        #php-memcached \
        php5-imagick \
        #php5-redis \
        php-pear \
    && pecl channel-update pecl.php.net \
    # Temporarily disable pear due to https://twitter.com/pear/status/1086634389465956352
    # && pear channel-update pear.php.net \
    # && pear upgrade-all \
    && pear config-set auto_discover 1 \
    && ln -sf /etc/php5/mods-available/mcrypt.in /etc/php5/cli/conf.d/20-mcrypt.ini \
    && ln -sf /etc/php5/mods-available/mcrypt.in /etc/php5/fpm/conf.d/20-mcrypt.ini \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer2 \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer1 --1 \
    && ln -sf /usr/local/bin/composer2 /usr/local/bin/composer \
    {{ services.php() }}
{%- endmacro %}

{% macro ubuntu12(role='') -%}
    # Install php environment
    && apt-install \
        # Install tools
        imagemagick \
        graphicsmagick \
        ghostscript \
        # Install php (cli/fpm)
        php5-cli \
        php5-fpm \
        php5-json \
        php5-intl \
        php5-imap \
        php5-curl \
        php5-mysqlnd \
        php5-mongodb \
        php5-mcrypt \
        php5-gd \
        php5-sqlite \
        php5-pgsql \
        php5-xmlrpc \
        php5-xsl \
        php5-geoip \
        php5-ldap \
        php5-memcache \
        #php-memcached \
        php5-imagick \
        #php5-redis \
        php-pear \
    && pecl channel-update pecl.php.net \
    # Temporarily disable pear due to https://twitter.com/pear/status/1086634389465956352
    # && pear channel-update pear.php.net \
    # && pear upgrade-all \
    && pear config-set auto_discover 1 \
    && ln -sf /etc/php5/mods-available/mcrypt.in /etc/php5/cli/conf.d/20-mcrypt.ini \
    && ln -sf /etc/php5/mods-available/mcrypt.in /etc/php5/fpm/conf.d/20-mcrypt.ini \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer2 \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer1 --1 \
    && ln -sf /usr/local/bin/composer2 /usr/local/bin/composer \
    {{ services.php() }}
{%- endmacro %}


{% macro ubuntu14(role='') -%}
    # Install php environment
    && apt-install \
        # Install tools
        imagemagick \
        graphicsmagick \
        ghostscript \
        # Install php (cli/fpm)
        php5-cli \
        php5-fpm \
        php5-json \
        php5-intl \
        php5-imap \
        php5-curl \
        php5-mysqlnd \
        php5-mongo \
        php5-mcrypt \
        php5-gd \
        php5-sqlite \
        php5-pgsql \
        php5-xmlrpc \
        php5-xsl \
        php5-geoip \
        php5-ldap \
        php5-memcache \
        php5-memcached \
        php5-imagick \
        php5-redis \
        php5-apcu \
        php-pear \
    && pecl channel-update pecl.php.net \
    # Temporarily disable pear due to https://twitter.com/pear/status/1086634389465956352
    # && pear channel-update pear.php.net \
    # && pear upgrade-all \
    && pear config-set auto_discover 1 \
    && ln -sf /etc/php5/mods-available/mcrypt.in /etc/php5/cli/conf.d/20-mcrypt.ini \
    && ln -sf /etc/php5/mods-available/mcrypt.in /etc/php5/fpm/conf.d/20-mcrypt.ini \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer2 \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer1 --1 \
    && ln -sf /usr/local/bin/composer2 /usr/local/bin/composer \
    {{ services.php() }}
{%- endmacro %}

{% macro ubuntu16(role='') -%}
    # Install php environment
    && apt-install \
        # Install tools
        imagemagick \
        graphicsmagick \
        ghostscript \
        # Install php (cli/fpm)
        php5-cli \
        php5-fpm \
        php5-json \
        php5-intl \
        php5-imap \
        php5-curl \
        php5-mysqlnd \
        php5-mongodb \
        php5-mcrypt \
        php5-gd \
        php5-sqlite \
        php5-pgsql \
        php5-xmlrpc \
        php5-xsl \
        php5-geoip \
        php5-ldap \
        php5-memcache \
        php5-imagick \
        php5-apcu \
    && pecl channel-update pecl.php.net \
    && ln -sf /etc/php5/mods-available/mcrypt.in /etc/php5/cli/conf.d/20-mcrypt.ini \
    && ln -sf /etc/php5/mods-available/mcrypt.in /etc/php5/fpm/conf.d/20-mcrypt.ini \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer2 \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer1 --1 \
    && ln -sf /usr/local/bin/composer2 /usr/local/bin/composer \
    {{ services.php() }}
{%- endmacro %}

